﻿Imports CoreClassLibraryCMS

Public Class GetBindBarang
    Inherits ProcessHelper.AbsProcess


    Public Overrides Function CreateProcess(User As String, Target As String, param As String) As System.Web.Mvc.JsonResult
        Dim Rec As New ADODBU.Recordset
        Dim Json As New Web.Mvc.JsonResult
        Dim Query, desc, itemid, size, color, barcode As String
        Dim SplitParam As String()
        Dim harga As Integer
        Dim DISC As Double

        SplitParam = param.Split("#")

        Query = " SELECT BARCODE, ARTCEXT, SIZE, COLOR, ARTDESC, "
        Query += "dbo.getValidSalesPrice ('SC001','" & SplitParam(0) & "','" & Format(CDate(SplitParam(1)), "yyyy-dd-MM") & "') AS PRICE, "
        Query += "dbo.getDiscount ('SC001','" & SplitParam(0) & "','" & Format(CDate(SplitParam(1)), "yyyy-dd-MM") & "') AS DISC "
        Query += " from dbo.ItemValidAssortment('SC001','" & Format(CDate(SplitParam(1)), "yyyy-dd-MM") & "','" & SplitParam(0) & "')"
        Rec.Open(Query, param, Connection.GetDBConnData)
        If Rec.ErrMessage.Length = 0 Then
            If Rec.RecordCount > 0 Then
                desc = Rec.Fields("ARTDESC")
                itemid = Rec.Fields("ARTCEXT")
                size = Rec.Fields("SIZE")
                color = Rec.Fields("COLOR")
                harga = Rec.Fields("PRICE")
                If IsDBNull(Rec.Fields("DISC")) Then
                    DISC = 0
                Else
                    DISC = Rec.Fields("DISC")
                End If
                barcode = Rec.Fields("BARCODE")
                Dim res = New With {.success = True, .DESCRIPT = desc, .ITEMID = itemid, .SIZE = size, .COLOR = color, .PRICE = harga, .DISC = DISC, .BARCODE = barcode}
                Json.Data = res
            Else
                Dim res = New With {.success = False}
                Json.Data = res
            End If
        End If

        Return Json
    End Function

    Public Overrides Function GetStatus() As String

    End Function
End Class
